﻿Public Class frmStocklist
    Dim Strsql As String
    Dim Mysql As New ClsSQLhelper
#Region "Function"

    Function Load_Data(Optional ByVal Str_Search As String = "") As Boolean
        Try
            Dim DT As New DataTable
            Load_Data = False
            Strsql = "select * from site "
            If Str_Search <> "" Then Strsql = Strsql & " WHERE site like '" & Me.TxtSearch.Text & "%' "
            Strsql = Strsql & " order by active desc,site"
            DT = Mysql.GetMYSQLDataTable(Strsql, "site")
            Pn_Framework.Set_GridSetting(Me.gridsite, DT)

            With gridsite
                .Columns(0).HeaderText = "รหัสคลัง"
                .Columns(0).Width = 80
                .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

                .Columns(1).HeaderText = "ชื่อคลังวัสดุ"
                .Columns(1).Width = 200

                .Columns(2).HeaderText = "หมายเหตุ"
                .Columns(2).Width = 350

                .Columns(3).HeaderText = "เปิดใช้งาน"
                .Columns(3).Width = 80
            End With

            Load_Data = True
        Catch ex As Exception
            Me.EventLog1.WriteEntry(Me.Name & " : " & ex.Message, EventLogEntryType.Error, 1)
            MsgBox(ex.Message)
        End Try
    End Function
#End Region
    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        Me.Dispose()
    End Sub
    Private Sub BtnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNew.Click
        FrmStockDetail.New_Entry_State = True
        FrmStockDetail.Show()
    End Sub
    Private Sub frmStocklist_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Load_Data()
    End Sub
    Private Sub BtnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
        FrmStockDetail.New_Entry_State = False
        FrmStockDetail.Txtid.Text = gridsite.Rows(gridsite.CurrentCell.RowIndex).Cells(0).Value.ToString
        FrmStockDetail.Txtname.Text = gridsite.Rows(gridsite.CurrentCell.RowIndex).Cells(1).Value.ToString
        FrmStockDetail.TxtNote.Text = gridsite.Rows(gridsite.CurrentCell.RowIndex).Cells(2).Value.ToString
        FrmStockDetail.ChkActive.Checked = gridsite.Rows(gridsite.CurrentCell.RowIndex).Cells(3).Value
        FrmStockDetail.Show()
    End Sub

    Private Sub TxtSearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtSearch.KeyDown
        If e.KeyCode = Keys.Enter Then
            If Me.TxtSearch.Text = "" Then
                Load_Data()
            Else
                Load_Data(Me.TxtSearch.Text)
            End If

        End If
    End Sub

    Private Sub gridsite_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gridsite.CellDoubleClick
        FrmStockDetail.New_Entry_State = False
        FrmStockDetail.Txtid.Text = gridsite.Rows(gridsite.CurrentCell.RowIndex).Cells(0).Value.ToString
        FrmStockDetail.Txtname.Text = gridsite.Rows(gridsite.CurrentCell.RowIndex).Cells(1).Value.ToString
        FrmStockDetail.TxtNote.Text = gridsite.Rows(gridsite.CurrentCell.RowIndex).Cells(2).Value.ToString
        FrmStockDetail.ChkActive.Checked = gridsite.Rows(gridsite.CurrentCell.RowIndex).Cells(3).Value
        FrmStockDetail.Show()
    End Sub

    Private Sub gridsite_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gridsite.CellContentClick

    End Sub
End Class